/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
$(function() {
    if (typeof(Storage) !== "undefined")
    {
        if (localStorage.profile_id == 0 || localStorage.profile_id == null) {
            wd_redirect('login.html');
        }
    } else {
        wd_redirect('login.html');
    }
    //logout
    var check_click_logout = false;
    $("#logout").click(function() {
        if (check_click_logout === false) {
            check_click_logout = true;
            var profile_id = 0;
            if (typeof(Storage) !== "undefined")
            {
                profile_id = localStorage.profile_id;
                facebook_token = localStorage.facebook_token;
                $.post(localStorage.domain_app+"/webservice/logout.php", {
                    profile_id: profile_id
                }, function(res) {
                    if (res == 1) {
                        print_alert("Your logout failed");
                    } else {
                       //console.log(res);
                        if (facebook_token !== "") {
                            FB.logout(function(response) {
                                // user is now logged out
                            });
                        }
                        localStorage.clear();
                        wd_redirect('login.html');
                    }
                }, "json");
            } else {
                return false;
            }
        }
    });
    
}
);

